// memoize 缓存 函数
const _ = require('lodash')

function area(r){
    console.log('222')
    return Math.PI *r * r
}
function tiji(x,y,z){
    return x*y*z
}

// let getAreaWithMemoize=_.memoize(area)
// let getTijiWithMemoize=_.memoize(tiji)

// console.log(getAreaWithMemoize(3))
// console.log(getTijiWithMemoize(3,4,5))


function memoize(fn){
    let cache={}
    return function(){
        let key_str= JSON.stringify(arguments)
        cache[key_str]=cache[key_str] || fn.apply(fn,arguments)
        return cache[key_str]
    }
}
let getAreaWithMemoize=memoize(area)
console.log(getAreaWithMemoize(5))
console.log(getAreaWithMemoize(5))

console.log(getAreaWithMemoize(5))
